<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/tagDeclare.jsp"%>
<%@include file="/headDeclare.jsp"%>
<html>
 <head>
<style type="text/css"> 
	fieldset,table,tr,td {margin:0; padding:0;}
	td {padding:0 5px 0 10px;border:1px;}
	form label {font-weight:bold;}
	table{border-collapse: collapse;}
  </style>

  <script type="text/javascript">
	$(document).ready(function() {
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            $("#userForm").submit();
        });
        //批量删除
        $("#btn_batch_del").click(function(){
        	var queryString = $("#userForm").formSerialize();
            queryString = encodeURIComponent(queryString);
        	var ids = null;
        	$("input[name='checkName']:checkbox:checked").each(function(){ 
        		if(ids == null)
        			ids = $(this).val();
        		else
        		    ids +=","+$(this).val() ;
        	}) ;
        	if(ids ==null)return;
        	if(ids == "")
        		{
        			$.ligerDialog.alert("请选择");
        			return;
        		}
        	location.href = "<%=basePath%>user/batchDelete.do?ids=" + ids +"&qs=" + queryString;
        });
  
      
	}); 
	
	function insert(){
        $.ligerDialog.open({ url: 'user/insert.do', height: 300, width: 400, buttons: [
            { text: '确定', onclick: function (item, dialog) {
            	dialog.frame.$("form:first").submit();
            },cls:'l-dialog-btn-highlight' },
            { text: '取消', onclick: function (item, dialog) { dialog.close(); } }
         ], isResize: true,title:'新增'
        });
    }
	
	function updateItem(id){
        $.ligerDialog.open({ url: 'user/update.do?id='+id, height: 300, width: 400, buttons: [
            { text: '确定', onclick: function (item, dialog) {
            	dialog.frame.$("form:first").submit();
            },cls:'l-dialog-btn-highlight' },
            { text: '取消', onclick: function (item, dialog) { dialog.close(); } }
         ], isResize: true,title:'修改'
        });
    }
	
	function deleteItem(id){
		var url = "<%=basePath%>user/delete.do";
		$.post(url,{id:id},function(data){
			var responseJson = eval('(' + data + ')');
			   if(responseJson.code==0)
			   {
				   $.ligerDialog.error("删除出错");
	         		return;
			   }else{
		    		window.pagerForm.submit();
			   }
		});
    	
	}
	function resetPwd(id){
		var url = "<%=basePath%>user/resetPwd.do";
		$.post(url,{id:id},function(data){
			var responseJson = eval('(' + data + ')');
			   if(responseJson.code==0)
			   {	
	         		return;
			   }else{
				   $.ligerDialog.alert(responseJson.info);
			   }
		});
    	
	}
	
  </script>
 </head>

 <body>
 
 <div style="width: 100%;">
  <div style="margin: auto;margin-top: 10px;" >
      <form id="userForm"  method="post" action="user/list.do">
        <table>
          <tr>
            <td><label for="name">用户名:</label></td>
            <td><input type="text" class="ldText" name="userName" id="username" value="${userName }"/></td>
            <td><input type="submit" id="btn_search" class="ldBtnBlue" value="查询"  /></td>
          </tr>
        </table>
      </form>
  </div>
  <hr />
  <div>
  	<table border="0" id="userTable" cellspacing="0" cellpadding="0" width="100%" class="ld-datagrid">
	    <tr>
	      <th align="center" >
               <span style="cursor: pointer" onclick="changeStatus('userTable','all')">全</span>/<span style="cursor: pointer" onclick="changeStatus('userTable','invert')">反</span>
		  </th>
          <th >用户名</th>
          <th >姓名</th>
          <th >操作</th>
 	    </tr> 
	  	<c:forEach items="${list}" var="user" varStatus="status">
	  	<tr>
	  	  <td>
	  	  	<input name="checkName" type="checkbox" <c:if test="${user.sysDefault==1}">disabled="disabled"</c:if> value="${user.id }" />
	  	  </td>
	  	  <td >${user.userName }</td>
	  	  <td >${user.showName }</td>
	  	  <td style="text-align: center;" >
	  	  	<input type="button" value="重置密码" class="ldBtnLink" onclick="resetPwd('${user.id }')"  />
  	  		<c:if test="${user.sysDefault==0 }">
  	  			<input type="button" value="修改" class="ldBtnLink" onclick="updateItem('${user.id }')" />
  	  			<input type="button" value="删除" class="ldBtnLink" onclick="deleteItem('${user.id }')" />
  	  		</c:if>
	  	  </td>
	  	</tr>
	  	</c:forEach>
  	</table>
  </div>
	<hr />
  <div>
  <div style="float: left;">
  	 <input type="button" id="btn_batch_del" class="ldBtnGray" value="批量删除" />
  	 <input type="button" id="btn_insert" onclick="insert()" value="新增" class="ldBtnGray" />
  </div>
      <div style="text-align:right;">
      <form action="user/list.do" name="pagerForm" id="pagerForm">
      	<input type="hidden" name="userName" value="${userName }" />
      	<jt:pager action="pagerForm"></jt:pager>
      </form>
      </div>
  </div>
 </div>
 </body>
</html>

